#ifndef CAN_MESSAGE_H
#define CAN_MESSAGE_H

/* Copyright (c) 2023 Reavis Co.Ltd. All rights reserved. */
/**
* @file crrc_can_analysis.h
* @brief TSCN & HUD CAN message analysis
* @author sxl
* @date 23/8/23
*/

#ifdef __cplusplus
extern "C"{
#endif

typedef unsigned char           UINT8;
typedef unsigned short int      UINT16;
typedef unsigned int            UINT32;
#if __WORDSIZE == 64
typedef unsigned long int	    UINT64;
#else
__extension__
    typedef unsigned long long int	UINT64;
#endif

/***********************************************************/
/* MACROS */
/***********************************************************/


/***********************************************************/
/* ENUMS */
/***********************************************************/
/**
* @brief hud switch
*/
typedef enum
{
    HUD_OFF     = 0,
    HUD_ON      = 1
}hud_switch_status;

/**
* @brief bright control mode
*/
typedef enum
{
    Bright_Ctr_AUTO     = 0,
    Bright_Ctr_MANUAL   = 1
}bright_ctr_mode;

/**
* @brief bright level
*/
typedef enum
{
    Bright_Level_ZERO   = 0,
    Bright_Level_ONE,
    Bright_Level_TWO,
    Bright_Level_THREE,
    Bright_Level_FOUR,
    Bright_Level_FIVE,
    Bright_Level_SIX,
    Bright_Level_SEVEN,
    Bright_Level_EIGHT,
    Bright_Level_NINE,
    Bright_Level_TEN    = 0x0A
}bright_level;

/**
* @brief motor level
*/
typedef enum
{
    Motor_Level_ZERO     = 0,
    Motor_Level_ONE,
    Motor_Level_TWO,
    Motor_Level_THREE,
    Motor_Level_FOUR,
    Motor_Level_FIVE,
    Motor_Level_SIX     = 0x06
}motor_level;

/**
* @brief self test status
*/
typedef enum
{
    SELFTEST_FAILED     = 0,
    SELFTEST_SUCCESSFUL = 1
}self_test_status;

/**
* @brief fault status
*/
typedef enum
{
    IS_NORMAL  = 0,
    IS_FAULT   = 1
}fault_status;

/***********************************************************/
/* UNIONS AND STRUCTS */
/***********************************************************/
/**
* @brief TSCN CAN Message
*/
typedef union
{
    UINT8 data[8];                        /**< message data from TSCN */

    struct
    {
        UINT8 RollingCounter[2];          /**< RollingCounter */

        UINT8 HUD_Switch;                 /**< HUD Switch */

        UINT8 AutoHudBrightSet;           /**< bright control mode */

        UINT8 HudBrightAdjmtReq;          /**< bright gear */

        UINT8 HudHeiAdjmtReq;             /**< height gear */

        UINT8 LightSensorVal[2];          /**< light sensor value */
    }msg_info;
}tscn_ctr_msg;

/**
* @brief TSCN CAN Message information extraction
*/
typedef union
{
    UINT8 data[8];
    struct
    {
        UINT16 RollingCounter;                /**< RollingCounter */

        hud_switch_status HUD_Switch;         /**< HUD Switch */

        bright_ctr_mode AutoHudBrightSet;     /**< bright control mode */

        bright_level HudBrightAdjmtReq;       /**< bright gear */

        motor_level HudHeiAdjmtReq;           /**< height gear */

        UINT16 LightSensorVal;                /**< light sensor value */
    }msg_info;

}tscn_ctr_val;

/**
* @brief HUD Status Message
*/
typedef union
{
    UINT8 data[8];                        /**< message data from HUD */

    struct
    {
        UINT8 RollingCounter[2];          /**< RollingCounter */

        UINT8 HudDisSta;                  /**< HUD show status */

        UINT8 AutoHudBrightSta;           /**< bright control mode */

        UINT8 HudBrightLevel;             /**< bright gear */

        UINT8 HudHeightLevel;             /**< height gear */

        UINT8 HUDSelfTest;                /**< HUD self test status */

        UINT8 CheckSum;                   /**< low 8 bits of the sum of the first seven bytes */
    }msg_info;
}hud_status_msg;

/**
* @brief HUD Status Message information extraction
*/
typedef union
{
    UINT8 data[8];
    struct
    {
        UINT16 RollingCounter;                /**< RollingCounter */

        UINT8 HudDisSta;          /**< HUD Switch status */

        UINT8 AutoHudBrightSta;     /**< bright control mode */

        UINT8 HudBrightLevel;                    /**< bright gear */

        UINT8 HudHeightLevel;                    /**< height gear */

        UINT8 HUDSelfTest;         /**< HUD self test status */

        UINT8 CheckSum;                       /**< low 8 bits of the sum of the first seven bytes */
    }msg_info;
}hud_status_val_data;





/**
* @brief HUD fault information Message
*/
typedef union
{
    UINT8 data[8];                       /**< message data from HUD */

    struct
    {
        UINT8 SupVolValue_L;             /**< supply voltage low 8 bits */

        UINT8 SupVolValue_H : 4;         /**< supply voltage high 4 bits */
        UINT8 SupVolLowDiag : 2;         /**< supply voltage low status */
        UINT8 SupVolHighDiag : 2;        /**< supply voltage high status */

        UINT8 TempOfPCBA;                /**< PCBA temperature */

        UINT8 TempOfDLP;                 /**< DLP temperature */

        UINT8 Reserved1;                 /**< Reserved */

        UINT8 TempOfMotor;               /**< Motor temperature */

        UINT8 PCBATempHighDiag : 2;      /**< PCBA TempHigh High */
        UINT8 Reserved2 : 4;             /**< Reserved */
        UINT8 MotorTempHighDiag : 2;     /**< Motor TempHigh High */


        UINT8 HudBusOffDiag : 1;         /**< HUD CAN bus off */
        UINT8 CommuTimeoutDiag : 1;      /**< Communication overtime */
        UINT8 CommuLoseDiag : 1;         /**< Communication lose */
        UINT8 MotorErrorDiag : 1;        /**< motor error */
        UINT8 VideoLoseDiag : 1;         /**< video lose */
        UINT8 HUDSelfTestDiag : 1;       /**< HUD self test error */
        UINT8 DLPErrorDiag : 2;          /**< DLP error */
    }msg_info;
}hud_dtc_msg;

/**
* @brief HUD fault information Message extraction
*/
typedef struct
{
    UINT16 SupVolValue;                  /**< supply voltage */

    fault_status SupVolLowDiag;          /**< supply voltage low status */

    fault_status SupVolHighDiag;         /**< supply voltage high status */

    UINT8 TempOfPCBA;                    /**< PCBA temperature */

    UINT8 TempOfDLP;                     /**< DLP temperature */

    UINT8 TempOfMotor;                   /**< Motor temperature */

    fault_status PCBATempHighDiag;       /**< PCBA TempHigh High */

    fault_status MotorTempHighDiag;      /**< Motor TempHigh High */

    fault_status HudBusOffDiag;          /**< HUD CAN bus off */

    fault_status CommuTimeoutDiag;       /**< Communication overtime */

    fault_status CommuLoseDiag;          /**< Communication lose */

    fault_status MotorErrorDiag;         /**< motor error */

    fault_status VideoLoseDiag;          /**< video lose */

    fault_status HUDSelfTestDiag;        /**< HUD self test error */

    fault_status DLPErrorDiag;           /**< DLP error */
}hud_dtc_val;

/**
* @brief HUD Soft&Hard version Message
*/
typedef union
{
    UINT8 data[8];                       /**< message data from HUD */

    struct
    {
        UINT8 SoftwareVersion1;           /**<  */

        UINT8 SoftwareVersion2;           /**<  */

        UINT8 SoftwareVersion3;           /**<  */

        UINT8 SoftwareVersion4;           /**<  */

        UINT8 HardwareVersion1;           /**<  */

        UINT8 HardwareVersion2;           /**<  */

        UINT8 HardwareVersion3;           /**<  */

        UINT8 HardwareVersion4;           /**<  */
    }msg_info;
}hud_version_msg;


/**
* @brief HUD Soft&Hard version Message information extraction
*/
typedef struct
{
    UINT32 Software_Version;             /**< Software Version */

    UINT32 Hardware_Version;             /**< Hardware Version */
}hud_version_val;




#ifdef __cplusplus
}

#endif




#endif // CAN_MESSAGE_H
